define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'keywords/keywords/index',
					edit_url: 'keywords/keywords/edit',
                    del_url: 'keywords/keywords/del',
                    multi_url: 'keywords/keywords/multi',
                    table: 'keywords',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'username', title: '会员账号', operate: 'LIKE'},
                        {field: 'url', title: '网址', operate: 'LIKE'},
                        {field: 'keyword', title: '关键词',},
                        {field: 'zhishu', title: '指数',},
						{field: 'chupai', title: '初排',},
                        {field: 'xinpai', title: '新排',},
                        {field: 'zuopai', title: '昨排',},
						{field: 'price', title: '单价',},
						{field: 'consumedays', title: '消费天数',},
						{field: 'addtime', title: '添加时间', formatter: Table.api.formatter.datetime,},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        edit: function () {
            Controller.api.bindevent();
        },
		recyclebin: function () {
			// 初始化表格参数配置
            Table.api.init({
                extend: {
					index_url: 'keywords/keywords/recyclebin' + location.search,
					dragsort_url: '',
                    table: 'keywords',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'username', title: '会员账号', operate: 'LIKE'},
                        {field: 'url', title: '网址', operate: 'LIKE'},
                        {field: 'keyword', title: '关键词',},
                        {field: 'zhishu', title: '指数',},
						{field: 'chupai', title: '初排',},
                        {field: 'xinpai', title: '新排',},
                        {field: 'zuopai', title: '昨排',},
						{field: 'price', title: '单价',},
						{field: 'consumedays', title: '消费天数',},
						{field: 'delete_time', title: '删除时间', operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime,},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'keywords/keywords/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'keywords/keywords/destroy',
                                    refresh: true
                                }
                            ],formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
		},
		restore: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});